package com.qf.controller;

import com.qf.annotation.ProccessInfo;
import com.qf.entity.Address;
import com.qf.exception.BizException;
import com.qf.exception.ControllerException;
import com.qf.service.AddressService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@CrossOrigin("*")
@RestController
@RequestMapping("/address")
public class AdressController {

    private AddressService addressService;


    public AdressController(AddressService addressService) {
        this.addressService = addressService;
    }

    @ProccessInfo(value = "获取用户信息", requireParamInfo = true)
    @GetMapping("/getById")//..../address/getById?id=1&statu=0
    public Object getById(int id,int state) {

        Address address = null;
        try {
            address = addressService.queryOne(id,state);
            System.out.println(address);
        } catch (BizException e) {
            throw e;
        } catch (Exception ex) {
            throw new ControllerException("控制层异常: " + ex.getMessage());
        }
        return address;
    }

    @ProccessInfo(value = "获取用户所有地址", requireParamInfo = true)
    @GetMapping("/getAll")//..../address/getAll?uid=1&statu=0
    public Object getAll(int uid,int statu) {

        List<Address> list=new ArrayList<>();
        Address address=null;
        try {
            list = addressService.getAll(uid,statu);
            System.out.println(address);
        } catch (BizException e) {
            throw e;
        } catch (Exception ex) {
            throw new ControllerException("控制层异常: " + ex.getMessage());
        }
        return list;
    }

    @ProccessInfo(value = "获取用户信息", requireParamInfo = true)
    @GetMapping("/set")//..../address/set?uId=1&aId=3
    public int updateSetStatus(int uid,int aid) {

        try {
            int updata = addressService.updateSetStatus(uid,aid);
        } catch (BizException e) {
            throw e;
        } catch (Exception ex) {
            throw new ControllerException("控制层异常: " + ex.getMessage());
        }
        return 0;
    }
}
